#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 310;
int f[N][N];
int n, m;
int h[N][N];
int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};

int dp(int x, int y)
{
    if (f[x][y] != -1)
    {
        return f[x][y];
    }

    f[x][y] = 1;
    for (int i = 0; i < 4; ++i)
    {
        int a = x + dx[i], b = y + dy[i];
        if (a >= 1 && a <= n && b >= 1 && b <= m && h[a][b] < h[x][y])
        {
            f[x][y] = max(f[x][y], dp(a, b) + 1);
        }
    }
    return f[x][y];
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            scanf("%d", &h[i][j]);
        }
    }
    memset(f, -1, sizeof(f));
    int ret = 1;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            ret = max(ret, dp(i, j));
        }
    }
    printf("%d", ret);
    return 0;
}